package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"jinrigaoping/rpc/sys/internal/svc"
	"jinrigaoping/rpc/sys/sys"

	"github.com/zeromicro/go-zero/core/logx"
)

type SysRoleDeleteLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSysRoleDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SysRoleDeleteLogic {
	return &SysRoleDeleteLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SysRoleDeleteLogic) SysRoleDelete(in *sys.SysRoleDeleteReq) (*sys.SysRoleDeleteRes, error) {

	if err := l.svcCtx.SysRoleModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {

		if err := l.svcCtx.SysRoleModel.TransDelete(ctx, session, in.Id); err != nil {
			return err
		}

		if err := l.svcCtx.SysRoleMenuModel.TransDelete(ctx, session, in.Id); err != nil {
			return err
		}

		return nil
	}); err != nil {
		return nil, err
	}

	return &sys.SysRoleDeleteRes{}, nil
}
